<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/_template.xhtml">
	<ui:define name="corpo">
		<p:messages />
		<h:form>
			<p:tabView effect="blind" effectDuration="normal">
				<p:tab title="#{msg['notafiscal.tab.titulo.notafiscal']}">
					<p:fieldset legend="#{msg['notafiscal.dadosNota']}">
						<p:outputLabel for="cnpj" value="#{msg['notafical.cnpj']}:" />
						<p:inputMask id="cnpj" mask="99.999.999/9999-99"
							value="#{notaFiscalBean.notaFiscal.cnpj}" converter="cnpj"
							converterMessage="#{msg['notafiscal.cpnj.conversao']}"/>

						<p:outputLabel for="data" value="#{msg['notafiscal.data']}" />
						<p:calendar id="data" pattern="dd/MM/yyyy"
							value="#{notaFiscalBean.notaFiscal.data.time}" />
					</p:fieldset>
				</p:tab>

				<p:tab title="#{msg['notafiscal.tab.titulo.Itens']}">
					<p:fieldset legend="#{msg['notafiscal.tab.titulo.dadosItens']}">
						<p:outputLabel for="produto" value="#{msg['notafiscal.produto']}:" />
						
						<p:autoComplete id="produto" value="#{notaFiscalBean.item.produto}" completeMethod="#{produtoBean.busca}"
							minQueryLength="3" var="produto" itemLabel="#{produto.nome}" itemValue="#{produto}">
						</p:autoComplete>
						
						<p:outputLabel for="quantidade"
							value="#{msg['notafiscal.quantidade']}:" />
						<p:inputText id="quantidade"
							value="#{notaFiscalBean.item.quantidade}" />

						<h:commandButton action="#{notaFiscalBean.guardaItem}"
							value="#{msg['notafiscal.btnAdicionarItem']}" />
					</p:fieldset>
				</p:tab>
				
				<p:tab title="#{msg['notafiscal.tab.titulo.grafico']}">
					<p:pieChart value="#{produtoBean.pieModel}" style="width:400px; height:300px" 
						showDataLabels="true" title="#{msg['notafiscal.quantidadeProduto']}" legendPosition="w"
					/>
				</p:tab>
			</p:tabView>

			<h:panelGroup rendered="#{not empty notaFiscalBean.notaFiscal.itens}">
			<h2>
				#{msg['notafiscal.titulo.listagem']}
			</h2>
			<h:dataTable value="#{notaFiscalBean.notaFiscal.itens}" var="item"
				styleClass="dados" rowClasses="impar, par" id="tabelaNota"
				binding="#{notaFiscalBean.tabela}">
				<h:column>
					<f:facet name="header">#{msg['notafiscal.tabela.col.produto']}</f:facet>
			    	#{item.produto.nome}
			    </h:column>
				<h:column>
					<f:facet name="header">#{msg['notafiscal.tabela.col.valorUnitario']}</f:facet>
					<h:outputText value="#{item.valorUnitario}">
						<f:convertNumber type="currency" currencySymbol="R$"
							locale="pt_BR" />
					</h:outputText>
				</h:column>
				<h:column>
					<f:facet name="header">#{msg['notafiscal.tabela.col.quantidade']}</f:facet>
			    	#{item.quantidade}
			    </h:column>
				<h:column>
					<f:facet name="header">#{msg['notafiscal.tabela.col.total']}</f:facet>
					<h:outputText value="#{item.total}">
						<f:convertNumber type="currency" currencySymbol="R$"
							locale="pt_BR" />
					</h:outputText>
				</h:column>
				<h:column>
					<h:commandLink value="Remover" action="#{notaFiscalBean.removeItem}" />
				</h:column>
			</h:dataTable>
			<h:commandButton value="#{msg['notafiscal.btnGravar']}" action="#{notaFiscalBean.gravar}" />
			</h:panelGroup>
		</h:form>
	</ui:define>
</ui:composition>
</html>